package comWorld.blog;

import java.util.List;

public class BlogInfos {
	private int userId;
	private List<BlogInfo> blogs;
	private int count;
	
	public BlogInfos() {
		userId = 0;
		blogs = null;
		count = 0;
	}
	
	public BlogInfos(int userId, List<BlogInfo> blogs) {
		this.userId = userId;
		this.blogs = blogs;
		this.count = blogs.size();
	}
	
	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}


	public List<BlogInfo> getBlogs() {
		return blogs;
	}


	public void setBlogs(List<BlogInfo> blogs) {
		this.blogs = blogs;
		count = blogs.size();
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
	
	public void add(BlogInfo blogInfo) {
		if (get(blogInfo.getBlogId()) == null)
 			blogs.add(0, blogInfo);
		count = blogs.size();
	}
	
	public void remove(int blogId) {
		for (int i = 0; i < blogs.size(); i++) {
			if (blogId == blogs.get(i).getBlogId()) {
				blogs.remove(i);
				break;
			}
		}
		count = blogs.size();
	}
	
	public BlogInfo get(int blogId) {
		BlogInfo blog = null;
		for (BlogInfo blogInfo : blogs) {
			if (blogInfo.getBlogId() == blogId) {
				blog = blogInfo;
				break;
			}
		}
		return blog;
	}
	
}
